package com.yricky.memoria.activity

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.lifecycle.ViewModelProvider
import com.yricky.memoria.data.pojo.PdfQuery
import com.yricky.memoria.ui.component.PdfActivityContent
import com.yricky.memoria.ui.component.PdfViewModel
import com.yricky.memoria.utils.gson
import com.yricky.memoria.utils.ws

/**
 * @author Yricky
 * @date 2021/12/11
 */
class PdfViewActivity:BaseActivity() {
    private val viewModel: PdfViewModel by lazy{
        ViewModelProvider(this)[PdfViewModel::class.java]
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val query: PdfQuery = try {
            gson.fromJson(intent.getStringExtra("query"), PdfQuery::class.java)
        }catch (e:Throwable){
            finish()
            return
        }
        ws.getPdf(query)?.let{
            viewModel.setPdf(query,it)
        } ?: let{
            finish()
            return
        }
        setContent {
            PdfActivityContent(viewModel = viewModel)
        }

    }
}